package com.treasure.service.common.controller;

import com.treasure.service.enums.CodeEnum;
import com.treasure.service.result.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.treasure.service.annotation.LogInfo;
import com.treasure.service.user.service.AppVersionCheckService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(value = "版本检查更新", description = "客户端检查更新")
@RestController
@RequestMapping("/version/v1")
public class AppCheckUpdateController {
	@Autowired
	private AppVersionCheckService appVersionCheckService;
	
	@LogInfo(log = "客户端检查更新", isPrint = true)
	@ApiOperation(value = "客户端检查更新", notes = "客户端检查更新")
	@PostMapping("/checkUpdate")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "osName", value = "系统名称", required = false, dataType = "String", paramType = "query"),
			@ApiImplicitParam(name = "versionCode", value = "系统版本号", required = false, dataType = "String", paramType = "query"),
			@ApiImplicitParam(name = "versionName", value = "系统版本描述", required = false, dataType = "String", paramType = "query") })
	public ResponseEntity checkUpdate(@RequestParam(value = "osName") String osName,
													  @RequestParam(value = "versionCode") int versionCode,
													  @RequestParam(value = "versionName") String versionName) {
		return ResponseEntity.ok(new ResponseResult(CodeEnum.SUCCESS,appVersionCheckService.checkUpdate(osName, versionCode)));
	}
}
